package org.yelongframework.excel.data.collect.sheet.manager;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yelongframework.excel.data.collect.sheet.SheetDataCollectMode;
import org.yelongframework.excel.data.collect.sheet.SheetDataCollector;

/**
 * 默认实现
 * 
 * @since 1.0.0
 */
public class DefaultSheetDataCollectorManager implements SheetDataCollectorManager {

	private static final Logger log = LoggerFactory.getLogger(DefaultSheetDataCollectorManager.class);

	/** 工作表数据填充器映射 */
	private final Map<SheetDataCollectMode, SheetDataCollector> sheetDataCollectorMap = new HashMap<>();

	// ==================================================注册==================================================

	@Override
	public void registerSheetDataCollector(SheetDataCollector sheetDataCollector) {
		SheetDataCollectMode sheetDataCollectMode = sheetDataCollector.getSheetDataCollectMode();
		SheetDataCollector sourceSheetDataCollector = getSheetDataCollector(sheetDataCollectMode);
		if (null != sourceSheetDataCollector) {
			log.info("数据收集器模式【" + sheetDataCollectMode + "】已存在【" + sourceSheetDataCollector + "】。以替换为【"
					+ sheetDataCollector + "】");
		}
		sheetDataCollectorMap.put(sheetDataCollectMode, sheetDataCollector);
	}

	@Override
	public void registerSheetDataCollectors(List<SheetDataCollector> sheetDataCollectors) {
		sheetDataCollectors.forEach(this::registerSheetDataCollector);
	}

	// ==================================================获取==================================================

	@Override
	public SheetDataCollector getSheetDataCollector(SheetDataCollectMode sheetDataCollectMode) {
		return sheetDataCollectorMap.get(sheetDataCollectMode);
	}

}
